using System;
using System.Collections;
using System.Globalization;

namespace Chaotic.DataBase.DataAccess
{
	public sealed class QueryParameterCollection : CollectionBase
	{
		public QueryParameter this[int index]
		{
			get
			{
				RangeCheck(index);
				return (QueryParameter)base.InnerList[index];
			}
			set
			{
				RangeCheck(index);
				Replace(index, value);
			}
		}

		public QueryParameter this[string? parameterName]
		{
			get
			{
				int index = RangeCheck(parameterName);
				return (QueryParameter)base.InnerList[index];
			}
			set
			{
				int index = RangeCheck(parameterName);
				Replace(index, value);
			}
		}

		public QueryParameter Add(QueryParameter param)
		{
			base.InnerList.Add(param);
			return param;
		}

		public QueryParameter Add(string? parameterName, object? value)
		{
			return Add(new QueryParameter(parameterName, value));
		}

		private void Replace(int index, QueryParameter newValue)
		{
			base.InnerList[index] = newValue;
		}

		private void RangeCheck(int index)
		{
			if (index < 0 || base.Count <= index)
			{
				throw new IndexOutOfRangeException("Number " + index.ToString(CultureInfo.InvariantCulture) + " is out of Range");
			}
		}

		private int RangeCheck(string? parameterName)
		{
			int num = IndexOf(parameterName);
			if (num < 0)
			{
				throw new IndexOutOfRangeException("ParameterName " + parameterName + " dose not exist");
			}
			return num;
		}

		public int IndexOf(string? parameterName)
		{
			int result = -1;
			for (int i = 0; i < base.InnerList.Count; i++)
			{
				if (((QueryParameter)base.InnerList[i]).ParameterName.Equals(parameterName))
				{
					result = i;
					break;
				}
			}
			return result;
		}
	}
}